$(function () {

    //日期
    $(".reservation").daterangepicker({
        locale : {
            format: 'YYYY-MM-DD',
            separator:' 到 ',
            applyLabel : '确定',
            cancelLabel : '取消',
            customRangeLabel : '自定义',
            daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
            monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                '七月', '八月', '九月', '十月', '十一月', '十二月' ],
            firstDay : 1
        },
        ranges: {
            '今天': [moment().startOf('day'), moment()],
            '昨天': [moment().subtract(1,'days').startOf('day'), moment().subtract(1,'days').endOf('day')],
            '本周': [moment().startOf("week").add(1,'days'),moment().endOf("week").add(1,'days')],
            '上周': [moment().subtract(1,'weeks').startOf("week").add(1,'days'),moment().subtract(1,'weeks').endOf("week").endOf("week").add(1,'days')],
            '本月': [moment().startOf("month"),moment().endOf("month")],
            '上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],
            '最近7天': [moment().subtract(6,'days'), moment()],
            '最近30天': [moment().subtract(29,'days'), moment()]
        },
        applyClass:'btn-primary',
        alwaysShowCalendars: true,
        autoclose:true
    });

    //信息核实查看
    var radios = $('#amountDataPhone input[type="radio"]');
    for (var i = 0; i < radios.length; i++) {
        if ($(radios[i]).prop('checked')) {
            if ($(radios[i]).next().text().trim() == '是') {
                $(radios).eq(i).parents('.col-sm-3.no-padding').next().hide();
            } else {
                $(radios).eq(i).parents('.col-sm-3.no-padding').next().show();
            }
        }

        $(radios[i]).click(function () {
            if ($(this).next().text().trim() == '是') {
                $(this).parents('.col-sm-3.no-padding').next().hide();
            } else {
                $(this).parents('.col-sm-3.no-padding').next().show();
            }
        })
    }

    //右侧按钮
    $(".tab_net li a").hover(function () {
        $(this).find("i").hide().next().show();
    }, function () {
        $(this).find("i").show().next().hide();
    })

    //待报考树结构
    //配置数据
    var data = [
        {
            "id": 1,
            "pId": 0,
            "name": "职业资格",
            "open": true,
        },
        {
            "id": 11,
            "pId": 1,
            "name": "01人力资源管理师[10人]",
        },
        {
            "id": 111,
            "pId": 11,
            "name": "2016年11月考期[5人]",
        },
        {
            "id": 112,
            "pId": 11,
            "name": "2017年11月考期[5人]",
        },
        {
            "id": 2,
            "pId": 0,
            "name": "学历",
            "open": true
        },
        {
            "id": 21,
            "pId": 2,
            "name": "03学历[20人]",
        },
        {
            "id": 211,
            "pId": 21,
            "name": "2016年9月[10人]",
        },
        {
            "id": 2111,
            "pId": 211,
            "name": "合作方1[10人]",
        },
        {
            "id": 21111,
            "pId": 2111,
            "name": "自考[10人]",
        },
        {
            "id": 211111,
            "pId": 21111,
            "name": "天津大学[10人]",
        },
        {
            "id": 2111111,
            "pId": 211111,
            "name": "一级[10人]",
        },
        {
            "id": 21111111,
            "pId": 2111111,
            "name": "计算机软件[10人]",
        },
        {
            "id": 21111112,
            "pId": 2111111,
            "name": "金融[10人]",
        },
        {
            "id": 2111112,
            "pId": 211111,
            "name": "二级[10人]",
        },
        {
            "id": 211112,
            "pId": 21111,
            "name": "北京大学[10人]",
        },
        {
            "id": 21112,
            "pId": 2111,
            "name": "远程[10人]",
        },
        {
            "id": 2112,
            "pId": 211,
            "name": "合作方2[10人]",
        },
        {
            "id": 21121,
            "pId": 2112,
            "name": "自考[10人]",
        },
        {
            "id": 21122,
            "pId": 2112,
            "name": "远程[10人]",
        },
        {
            "id": 212,
            "pId": 21,
            "name": "2017年9月[10人]",
        },
        {
            "id": 2121,
            "pId": 212,
            "name": "合作方3[10人]",
        },
        {
            "id": 2122,
            "pId": 212,
            "name": "合作方4[10人]",
        }
    ];

    var setting = {
        view: {
            addDiyDom: addDiyDom
        },
        check: {
            enable: false,
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };
    function addDiyDom(treeId, treeNode) {
        var aObj = $("#" + treeNode.tId + "_a");

        if (treeNode.id == 1 || treeNode.id == 2) {
            return;
        }

        var operateStr = ""
            + "<span class='view-btn blue' id='diyBtn1_" + treeNode.id
            + "'title='" + treeNode.name + "''>查看</span>"
            + "<span class='apply-btn blue' id='diyBtn2_" + treeNode.id
            + "'title='" + treeNode.name + "''>申请</span>";
        aObj.append(operateStr);

        //查看
        var viewBtn = $("#diyBtn1_" + treeNode.id);
        viewBtn.on("click", function () {
        	$(this).parents(".wait_tree").hide()
        	$(".waitExamInfo").show().addClass('animated bounceInRight');
        	
        });
        
        //返回
        $("#waitExam").on("click",".back_tree",function(){
        	$(this).parents(".waitExamInfo").hide();
        	$(".wait_tree").show();
        })


        //申请
        var applyBtn = $("#diyBtn2_" + treeNode.id);
        applyBtn.on("click", function () {
			
        });
    };

    $.fn.zTree.init($("#waitExamTree"), setting, data);

})

//折叠

	$(".collapse-btn").click(function() {
		$(this).parent().parent().siblings().toggle();
	})

